home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH15 / EX15_2.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-03-25  |  1.9 KB  |  113 lines

  1. ; EX15_2.asm
  2. ;
  3. ; This program compares the performance of the MOVS instruction against
  4. ; a manual block move operation.  It also compares MOVS against a LODS/STOS
  5. ; loop.
  6.  
  7.         .386
  8.         option        segment:use16
  9.  
  10.         include     stdlib.a
  11.         includelib    stdlib.lib
  12.  
  13.  
  14. dseg        segment    para public 'data'
  15.  
  16. Buffer1        byte    2048 dup (0)
  17. Buffer2        byte    2048 dup (0)
  18.  
  19. dseg        ends
  20.  
  21.  
  22. cseg        segment    para public 'code'
  23.         assume    cs:cseg, ds:dseg
  24.  
  25. Main        proc
  26.         mov    ax, dseg
  27.         mov    ds, ax
  28.         mov    es, ax
  29.         meminit
  30.  
  31.  
  32. ; MOVSB version done here:
  33.  
  34.         print
  35.         byte    "The following code moves a block of 2,048 bytes "
  36.         byte    "around 100,000 times.",cr,lf
  37.         byte    "The first phase does this using the movsb "
  38.         byte    "instruction; the second",cr,lf
  39.         byte    "phase does this using the lods/stos instructions; "
  40.         byte    "the third phase does",cr,lf
  41.         byte    "this using a loop with MOV instructions.",cr,lf,lf,lf
  42.         byte    "Press any key to begin phase one:",0
  43.  
  44.         getc
  45.         putcr
  46.  
  47.         mov    edx, 100000
  48.  
  49. movsbLp:    lea    si, Buffer1
  50.         lea    di, Buffer2
  51.         cld
  52.         mov    cx, 2048
  53.     rep    movsb
  54.         dec    edx
  55.         jnz    movsbLp
  56.  
  57.         print
  58.         byte    cr,lf
  59.         byte    "Phase one complete",cr,lf,lf
  60.         byte    "Press any key to begin phase two:",0
  61.  
  62.         getc
  63.         putcr
  64.  
  65.         mov    edx, 100000
  66.  
  67. LodsStosLp:    lea    si, Buffer1
  68.         lea    di, Buffer2
  69.         cld
  70.         mov    cx, 2048
  71. lodsstoslp2:    lodsb
  72.         stosb
  73.         loop    LodsStosLp2
  74.         dec    edx
  75.         jnz    LodsStosLp
  76.  
  77.         print
  78.         byte    cr,lf
  79.         byte    "Phase two complete",cr,lf,lf
  80.         byte    "Press any key to begin phase three:",0
  81.  
  82.         getc
  83.         putcr
  84.  
  85.         mov    edx, 100000
  86.  
  87. MovLp:        lea    si, Buffer1
  88.         lea    di, Buffer2
  89.         cld
  90.         mov    cx, 2048
  91. MovLp2:        mov    al, ds:[si]
  92.         mov    es:[di], al
  93.         inc    si
  94.         inc    di
  95.         loop    MovLp2
  96.         dec    edx
  97.         jnz    MovLp
  98.  
  99.  
  100. Quit:        ExitPgm            ;DOS macro to quit program.
  101. Main        endp
  102.  
  103. cseg        ends
  104.  
  105. sseg        segment    para stack 'stack'
  106. stk        db    1024 dup ("stack   ")
  107. sseg        ends
  108.  
  109. zzzzzzseg    segment    para public 'zzzzzz'
  110. LastBytes    db    16 dup (?)
  111. zzzzzzseg    ends
  112.         end    Main
  113.